<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	template="/resources/layout/templateInterno.xhtml"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:rich="http://richfaces.org/rich">
    
    
	<ui:define name="body">
		<div class="form">
		<h:form id="formEnviarEmail">
		<h:panelGroup id="pgMensagens">
						<h:messages layout="table" errorClass="errorMessage" infoClass="infoMessage" />
		</h:panelGroup>
		<div  class="field-clear"></div>
		  <t:fieldset id="idfsDadosEnvio"  legend="Dados">
		  
		  		<div class="grid-5-12">
					<h:outputLabel id="lbTitulo" class="form-lbl"  value="Título:"/>
					<h:inputText  id="inptTitulo" required="true" label="Título:" style="text-transform: none;" styleClass="form-txt" value="#{enviarEmailBean.titulo}" />
				</div> 
				<div class="field-clear"></div>
				<div class="grid-4-12">
					<h:outputLabel  id="lbOpcTipoEnvio" class="form-lbl"  value="Enviar e-mail:"/>
					<h:selectOneRadio id="cbOpcTipoEnvio" required="true" label="Enviar e-mail" value="#{enviarEmailBean.opcTpEnvio}">
						  <f:selectItem itemLabel="Selecionar Destinatário" itemValue="D" />
						  <f:selectItem itemLabel="Grupo" itemValue="G" />
					<a4j:support  event="onclick" ajaxSingle="true" action="#{enviarEmailBean.limparLista}" reRender="pgTipoEnvioGrupo, pgTipoEnvioDestinatario,pgExibirTable"></a4j:support>  
					</h:selectOneRadio>	
				</div>
				<h:panelGroup id="pgTipoEnvioGrupo">
					<h:panelGroup rendered="#{enviarEmailBean.opcTpEnvio eq 'G'}"  >
					<div class="grid-3-12">
							<h:outputLabel id="lbSexo" class="form-lbl"  value="Enviar Para:"/>
							<h:selectOneMenu   id="cbSexo" styleClass="form-txt" value="#{enviarEmailBean.opcEnvio}">
						 		 <f:selectItem itemLabel="SELECIONE..." itemValue=""/>
						 		<f:selectItem itemLabel="POR IGREJA" itemValue="PI"/>					 		
						 		<f:selectItem itemLabel="TODAS IGREJAS" itemValue="TI"/>
						 		<a4j:support  event="onchange" ajaxSingle="true" reRender="pgIgrejaFrequenta,formEnviarEmail" action="#{enviarEmailBean.totdasIgrejas}" ></a4j:support>
					 		</h:selectOneMenu>
						</div>
				<h:panelGroup id="pgIgrejaFrequenta">
				 	<h:panelGroup  rendered="#{enviarEmailBean.opcEnvio eq 'PI'}" >
						<div class="grid-3-12">
							<h:outputLabel  id="lbIgreja"  class="form-lbl"  value="Igreja:"/>
							<h:selectOneMenu converter="indexConverter" label="Igreja:"  id="cbIgreja"  value="#{enviarEmailBean.igreja}">
								   <f:selectItem itemLabel="SELECIONE..." itemValue=""/>
								   <t:selectItems value="#{enviarEmailBean.listaIgreja}" var="igreja" itemLabel="#{igreja.nome}" itemValue="#{igreja}"/>
								   <a4j:support  event="onchange" ajaxSingle="true" reRender="pgMsgTpEnvio,pgExibirTable,formEnviarEmail" action="#{enviarEmailBean.membroPorIgreja}" ></a4j:support>
							</h:selectOneMenu>					
							</div>
					</h:panelGroup>
				</h:panelGroup>
						<h:panelGroup id="pgMsgTpEnvio">
							<h:panelGroup rendered="#{enviarEmailBean.exibirMensagem}"  >
								  <div class="grid-12-12">
								  	<div  style="margin-top: 10px; margin-left: 150px">
										<h:outputText value="#{msg['info.MGS_01']}"  />
									</div>
								 </div>
						 </h:panelGroup>
					 	</h:panelGroup>
					 <div class="field-clear"></div>
					</h:panelGroup>
				</h:panelGroup>
				<div class="field-clear"></div>
				<h:panelGroup id="pgTipoEnvioDestinatario">
					<h:panelGroup rendered="#{enviarEmailBean.opcTpEnvio eq 'D'}"  >
						<a4j:region>
							<div class="grid-4-12">
								<h:outputLabel  id="lbMembroNome" class="form-lbl"  value="Destinatário:"/>
								 <h:inputText styleClass="form-txt"  required="true" value="#{enviarEmailBean.membro}" label="DestinatÃ¡rio" id="text" />
											<rich:suggestionbox ajaxSingle="true" id="suggestionBoxId"
												for="text" suggestionAction="#{enviarEmailBean.autocomplete}"
												var="membro" fetchValue="#{membro.nome}"
												rows="#{suggestionBox.intRows}"
												nothingLabel="Nenhum membro encontrado." 
												style="text-transform: uppercase;"
												>
				
												<h:column>
													<h:outputText value="#{membro.nome}" />
												</h:column>
				
												<a4j:support event="onselect">
													<f:setPropertyActionListener value="#{membro}" target="#{enviarEmailBean.membroSelecionado}" />
												</a4j:support>
											</rich:suggestionbox>
		
								</div>	
						</a4j:region>
						 <div  class="grid-2-12">
						 	<div  style="margin-top: 23px">
								<a4j:commandButton style="width:70px" ajaxSingle="true"  styleClass="form-button" id="cbAdicionar" value="Adicionar" reRender="pgTipoEnvioDestinatario,pgMensagens,pgExibirTable,lbMembroNome" action="#{enviarEmailBean.adicionar}" >	</a4j:commandButton>
							</div>
						</div >	
					</h:panelGroup>
				</h:panelGroup>
			
			
			<div class="field-clear"></div>
			<h:panelGroup id="pgExibirTable">
				<h:panelGroup   >
				 <div class="grid-10-12" style="text-align: center" >
					 <rich:dataTable  rendered="#{not empty enviarEmailBean.listaMembroEnviar}"
	                    			     rowClasses="odd, even" rows="10"
	                    			styleClass="dataTable rich-table rich-table-cell ui-widget-content ui-grid-content"
		                    			width="600" border="0" align="center" id="membroTable"  var="membro" value="#{enviarEmailBean.listaMembroEnviar}" >
						  <f:facet  name="header">
		                    <rich:columnGroup >
		                            <rich:column  style="text-align: center; width:300px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="Nome" /></strong>
		                            </rich:column>
		                             <rich:column style="text-align: center; width:200px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="E-mail" /></strong>
		                            </rich:column>
		                             <rich:column style="text-align: center; width:200px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="Último E-mail Enviado" /></strong>
		                            </rich:column>
		                             <rich:column style="text-align: center; width:100px"  styleClass="ui-state-default" >
		                                <strong><h:outputText value="Ação" /></strong>
		                            </rich:column>
		                    	</rich:columnGroup>
		                  </f:facet>
		 				<rich:columnGroup >	
		 					<rich:column  style="text-align: center;" >
								<h:outputText value="#{membro.nome}" />
							</rich:column>	
							<rich:column  style="text-align: center;" >
								<h:outputText value="#{membro.email}" />
							</rich:column>	
							<rich:column  style="text-align: center;" >
								<a4j:commandLink id="visualizar" oncomplete="Richfaces.showModalPanel('panelEmailHistorio');" ajaxSingle="true" action="#{enviarEmailBean.verEmailUltimoHistirico}" reRender="pGPopupEmailHistorio"  >
									 <h:graphicImage value="/resources/imagens/visualizar.jpg" id="gIVisualizar" styleClass="hidelink"/>
									 <f:setPropertyActionListener target="#{enviarEmailBean.emailHistorico}" value="#{membro.emailUltimoHistorico}"/>  
								</a4j:commandLink>
							</rich:column>	
							<rich:column style="text-align: center;" >
								<a4j:commandLink id="remover" ajaxSingle="true" action="#{enviarEmailBean.excluir}" reRender="pgMensagens,pgExibirTable"  >
									 <h:graphicImage value="/resources/imagens/ico_excluir.gif" id="gIExcluir" styleClass="hidelink"/>
									 <f:setPropertyActionListener target="#{enviarEmailBean.membroExcluir}" value="#{membro}"/>  
								</a4j:commandLink>
							</rich:column>
						</rich:columnGroup>
					</rich:dataTable>
				</div>
				 <div class="field-clear"></div>
			<div class="grid-12-12">
				<rich:datascroller align="center" status="" renderIfSinglePage="false" for="membroTable" />
			</div>
			</h:panelGroup>
		</h:panelGroup>
		 </t:fieldset>
		<div  class="grid-12-12">
			<rich:editor style="height:180px" value="#{enviarEmailBean.textoEmail}" id="editorEmail" theme="advanced" />
		</div>
		<div style="margin-left: 300px" class="field-clear"></div>
		  <div  class="grid-2-12">
			 	<div  style="margin-top: 23px; margin-left: 350px">
					<a4j:commandButton ajaxSingle="true" style="width:80px"  styleClass="form-button" id="cbEnviar" process="inptTitulo,editorEmail" value="Enviar" reRender="pgMensagens,membroTable,formEnviarEmail" action="#{enviarEmailBean.enviar}" >	</a4j:commandButton>
				</div>
			</div >	
		</h:form>
		
		<h:panelGroup id="pGPopupEmailHistorio"  >
			
		<rich:modalPanel id="panelEmailHistorio" width="900" height="500"   resizeable="false">
		
			<f:facet name="header">Último E-mail Enviado</f:facet>
				 <f:facet name="controls">
			            <h:panelGroup>
			            <h:form>
			              	<a4j:commandLink  onclick="Richfaces.hideModalPanel('panelEmailHistorio')" >
			              		<h:graphicImage value="/resources/imagens/close.png" id="giAdd" styleClass="hidelink"/>
			              	</a4j:commandLink>
			              </h:form>	                
			            </h:panelGroup>
			        </f:facet>
			
			<h:form id="verDetalhesMural" styleClass="form">
			<div class="grid-12-12"  > 
				
				<h:panelGroup style="width:800px" id="pgEmailHistorico">
					<h:panelGroup style="width:800px" id="pgEmailHistoricoConteudo">
						 
						<div class="grid-4-12">
								<h:outputLabel  id="lbNoUsuario" class="form-lbl"  value="Enviado Por:"/>
								<h:inputText  id="inptNoUsuario" disabled="true" styleClass="form-txt" value="#{enviarEmailBean.emailHistorico.noUser}" />					
						</div>
						<div class="grid-4-12">
								<h:outputLabel  id="lbDtEnvio" class="form-lbl"  value="Data de Envio:"/>
								<h:inputText  id="inptDtEnviro" styleClass="form-txt" disabled="true" value="#{enviarEmailBean.emailHistorico.dtEnvio}" >
									<f:convertDateTime pattern="dd/MM/yyyy HH:mm"/>  
								</h:inputText>					
						</div>  
						<div class="field-clear"></div>
						<div class="grid-4-12">
								<h:outputLabel  id="lbTitulo" class="form-lbl"  value="Título:"/>
								<h:inputText  id="inptTitulo" styleClass="form-txt" disabled="true" value="#{enviarEmailBean.emailHistorico.titulo}" />					
						</div> 
						<div class="field-clear"></div>
						<div class="grid-7-12">
						<h:outputLabel id="lbMensagem" class="form-lbl" value="Mensagem:" />
						 <h:inputTextarea style="width: 700px; height: 150px" disabled="true" styleClass="form-txt" value="#{enviarEmailBean.emailHistorico.mensagemFormatada}" >
						  <f:validateLength maximum="100"></f:validateLength>
						 </h:inputTextarea>
					</div>	
					</h:panelGroup>	
				</h:panelGroup>
				
			</div>
				                     
			</h:form>
			
			
		</rich:modalPanel>
		
		</h:panelGroup>
		
		</div>
		<t:saveState value="#{enviarEmailBean.emailHistorico}"></t:saveState>
		<t:saveState value="#{enviarEmailBean.titulo}"></t:saveState>
		<t:saveState value="#{enviarEmailBean.membroExcluir}"></t:saveState>
		<t:saveState value="#{enviarEmailBean.tpEnvio}"></t:saveState>
		<t:saveState value="#{enviarEmailBean.opcTpEnvio}"></t:saveState>
		<t:saveState value="#{enviarEmailBean.textoEmail}"></t:saveState>
		<t:saveState value="#{enviarEmailBean.membroSelecionado}"></t:saveState>
		<t:saveState value="#{enviarEmailBean.listaMembroEnviar}"></t:saveState>
		<t:saveState value="#{enviarEmailBean.emailHistorico}"></t:saveState>
		<t:saveState value="#{enviarEmailBean.opcEnvio}"></t:saveState>
	</ui:define>
</ui:composition>

